package com.itheima.controller;

import com.itheima.ws.pojo.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;
import com.itheima.ws.pojo.Result;


@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 登录
     * @param user
     * @param session
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpSession session) {
        Result result = new Result();
        if (user != null && "123".equals(user.getPassword())) {
            result.setIs_system(true);
//            result.setFromName(user.getName());
            result.setMessage("登陆成功");
            session.setAttribute("user", user.getName());
        } else {
            result.setIs_system(false);
            result.setMessage("登陆失败");
        }
        return result;
    }

    @GetMapping("/hi")
    public String hi() {
        System.out.println("hi");
        return "hi";
    }
}
